<?
include('header.php');

if(!$is_online){
	redirect('index.php');
	exit;
}

$sql = $db->Query("SELECT id FROM `twitter` WHERE `active`='0' AND `user`='".$data['id']."'");
$query = $db->GetNumRows($sql);

$sql = $db->Query("SELECT id,t_name,t_av,cpc FROM `twitter` WHERE (`active` = '0' AND `points` >= `cpc`) AND (`id` NOT IN (SELECT `site_id` FROM `followed` WHERE `user_id`='".$data['id']."') AND `user`!='".$data['id']."') ORDER BY `cpc` DESC LIMIT 7");
$ext = $db->GetNumRows($sql);
$sites = $db->FetchArrayAll($sql);
?>
<div class="block medium right">
			<div class="top">
                  <h1>Earn Coins - Twitter</h1>
            </div>
			<div class="content">	
<?
if($query > 0){
if($ext > 0){
?>
<p>Press "Follow" on this page and after that press "Follow" on twitter page. After that, press on "Confirm".</p>
<script>
function skipuser(str,username) {
document.getElementById("txtHint").style.display='block';
	$("#txtHint").html('<table cellpadding="2" cellspacing="0" width="500" align="center" class="maintable"><tr><td align="center"><font size="3"><b>Skipping @'+username+'</b></font></td></tr><tr><td><center><font size=2><b>Skipping... <img src="img/ajax-loader.gif"></b></font></center></td></tr></table><br>');
	$.ajax({
		type: "GET",
		url: "pages/follow.php?step=skip",
		data: "id="+str,
		success: function(msg){
			$("#txtHint").html(msg);
		}
	});
	remove(str);
}
function followuser(str,username)
{
document.getElementById("txtHint").style.display='block';
	$("#txtHint").html('<table cellpadding="2" cellspacing="0" width="500" align="center" class="maintable"><tr><td align="center"><font size="3"><b>Did you follow @'+username+'?</b></font></td></tr><tr><td><center><font size=2><b>Verifying... <img src="img/ajax-loader.gif"></b></font></center></td></tr></table><br>');
	$.ajax({
		type: "GET",
		url: "pages/follow.php",
		data: "id="+str,
		success: function(msg){
			$("#txtHint").html(msg);
		}
	});
}

function remove(Variable) {
document.getElementById(Variable).style.display='none';
}
</script>
<center><div id="txtHint" style="display:none;"></div></center>
<div id="getpoints">
<?
  foreach($sites as $site){
?>	
<div class="follow" id="<?=$site['id']?>"><center><img src="<?=$site['t_av']?>" border="0" alt="@<?=$site['t_name']?>" width="48" height="48" class="follower"><br><b>Coins</b>: <?=$site['cpc']?><br><center><a href="javascript:void(0);" onclick="window.open('http://twitter.com/<?=$site['t_name']?>','Twitter','status=0,toolbar=0,width=1000,height=500,resizable=0,menubar=0,location=0,directories=0');" class="followbutton">Follow</a>
<a href="javascript:void(0);" onclick="followuser('<?=$site['id']?>','<?=$site['t_name']?>');" class="followbutton">Confirm</a>
</center><font style="font-size:0.8em;">[<a href="javascript:void(0);" onclick="skipuser('<?=$site['id']?>','<?=$site['t_name']?>');remove('<?=$site['id']?>');" style="color: #666666;font-size:0.9em;">skip</a>]</font></center></div>
<?}?>
</div>
<br>
<div class='infobox'><form action='' method='' onsubmit='refreshpage();'><input name='refresh' type='submit' value='Refresh'></form></div>
<?}else{?>
<div class="msg">
<div class="error">Sorry, there are no more coins to be earned at the moment. Please try again later.</div>
<div class="info"><a href="buy.php"><b>Feel like you need more coins? You can purchase them now!</b></a></div></div>
<?}}else{?>
<div class="msg"><div class="error"><a href="twitterconfig.php">Add your Twitter account first!</a></div></div>
<?}?>
				</div>
			</div>		
<?include('footer.php');?>